<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>周月核查</title>
    <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
</head>
<body>
<div class="easyui-container-fluid">
    <div class="easyui-panel" style="border:none;">
        <div class="nav" id="nav"></div>
        <div class="easyui-panel" style="border:none;">
            <form id="ff">
                <div style="margin-bottom:20px;">
                            <span>
                            <label class="item-label">年份：</label>
                            <input type="text" class="easyui-combobox" name="year" id="year" style="width:100px;"/>
                            </span>
                    <span id="monthLabel">
                            <label class="item-label">月份：</label>
                            <input type="text" class="easyui-combobox" name="month" id="month" style="width:100px;"/></span>
                    <span id="weekLabel">
                            </span>
                    <label class="item-label">品类：</label>
                    <input type="text" id="categorySelect" name="categoryCodes" class="easyui-combobox" data-options="panelHeight:'150'" style="width:6%"/>

                    <label class="item-label">筛选条件：</label>
                    <select id="selectType" name="selectType" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:5%;">
                        <!--<option value="PRICE">价格</option>-->
                        <option value="COUNT">差值</option>
                        <option value="MWRATIO">月/周</option>
                    </select>
                    <select id="comparerbox" name="comparator" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:5%;" prompt="比较符">
                        <option value="GREAT">&gt;</option>
                        <option value="GREAT_EQUAL">&gt;=</option>
                    </select>
                    <input type="text" id="valuebox" name="value" class="easyui-textbox" prompt="数值"value="50" data-options="" style="width:4.8%"/>

                    <a href="javascript:void(0);" style="margin-left:40px;width:80px;" class="easyui-linkbutton c8" onclick="searchBy()">查询</a>
                    <!--同商场同型号月量比4周量大的调整为4周的量-->
                    <a href="javascript:void(0);" style="margin-left:40px;width:80px;" class="easyui-linkbutton c8" onclick="countAdjustment()">月量调整</a>
                </div>
                <div style="margin-left: 3%"><span style="color: #5b81b3">注意：只显示月销量大于10的结果 </span></div>
            </form>
        </div>
        <div class="table-wrapper " >
            <table id="datagrid">
                <thead>
                <tr>
                    <!--<th data-options="field:'categoryName',align:'center'" width="80">品类</th>-->
                    <th data-options="field:'categoryCode',align:'center'" width="80">商场码</th>
                    <!--<th data-options="field:'categoryName',align:'center'" width="80">商场名</th>-->
                    <th data-options="field:'modelCode',align:'center'" width="80">型号码</th>
                    <th data-options="field:'modelName',align:'center'" width="80">型号名</th>
                    <th data-options="field:'count',align:'center',formatter:zeroReplace" width="100"><span style='color: red'>月销量</span></th>
                    <th data-options="field:'count1',align:'center',formatter:zeroReplace" width="100"><span style='color: red'>4周销量</span></th>
                    <th data-options="field:'cz',align:'center',formatter:zeroReplace" width="100"><span style='color: red'>差值</span></th>
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    $(function () {
        setNav();
        // initCategoryMultiple();
        initUserCategorySelect("categorySelect")
        initMonthWeek("monthLabel","weekLabel");
        $('#channelCodeMulti').textbox({
            icons: [{
                iconCls: 'icon-clear', handler: function (e) {
                    $(e.data.target).textbox('clear');
                }
            }]
        });
        var height = $(window).height();
        var ff_height = $("#ff").height();
        var table_height = height - ff_height - 60;
        $("#datagrid").css("max-height", table_height);
        $("#datagrid").datagrid({
            rownumbers: true,
            // pagination: true,
            singleSelect: true,     //是否单选
            idField: "id",
            checkOnSelect: false,
            fitColumns:true,    //自动适应分辨率
            scrollbarSize:0     //滚动条大小
        }).datagrid("getPager").pagination({
            onSelectPage: searchBy
        });
    });
    aRecords("周月对比","/webapp/pages/product/audit/mwControl")
    function searchBy(){
        var data = getFormData(document.getElementById("ff"));
        if(data.value<10 &&data.selectType == "COUNT"){
            $.messager.alert("提示", "差值请大于10", "error");
            return;
        }
        $.ajax({
            type:"get",
            url:config.url + "/categoryMiss/control",
            data:transfer(data),
            dataType: "json",
            xhrFields:{withCredentials:true},
            beforeSend:function () {
                $.messager.progress({
                    title:"请稍等",
                    interval:50,
                    text:"数据加载中..."
                });
            },
            success:function(data){
                $.messager.progress("close");
                if (data.code == 200) {
                    $("#datagrid").datagrid("loadData", data.msg.content);
                }else {
                    $.messager.alert("提示", data.msg, "error");
                }
            },
            error:function(data){
                $.messager.progress("close");
            }
        });
    }
    function countAdjustment(){
        var data = getFormData(document.getElementById("ff"));
        if(data.value<50){
            $.messager.alert("提示", "只允许处理差值大于50", "error");
            return;
        }
        $.ajax({
            type:"get",
            url:config.url + "/categoryMiss/countAdjustment",
            data:transfer(data),
            dataType: "json",
            xhrFields:{withCredentials:true},
            beforeSend:function () {
                $.messager.progress({
                    title:"请稍等",
                    interval:50,
                    text:"数据加载中..."
                });
            },
            success:function(data){
                $.messager.progress("close");
                if (data.code == 200) {
                    $.messager.alert("提示", data.msg, "info",function () {
                        searchBy();
                    });
                }else {
                    $.messager.alert("提示", data.msg, "error");
                }
            },
            error:function(data){
                $.messager.progress("close");
            }
        });
    }

    function zeroReplace(val,row) {
        if (val == 0) {
            return "";
        }else {
            return val;
        }
    }

</script>
</html>